<?php
/**
 * Created by Zhy
 * User: Zhy
 * Date: 2023/12/14
 * Time: 14:37
 */

namespace app\api\model;

class Order extends Base
{
    /**
     * 插入订单表
     * @param $data
     * @return int|string
     */
    static function insertOrder($data = []){
        return self::insertGetId($data);
    }

    /**
     * 统计
     * @param $where
     * @param $field
     * @return bool|\PDOStatement|string|\think\Collection
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    static function countOrder($where = [], $field = 'order_id'){
        return self::where($where)->where('order_delete', 1)->count($field);
    }

    /**
     * 查询订单列表
     * @param $where
     * @param $field
     * @param $page
     * @return array
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    static function selectOrder($where = [], $field = '*', $page = 1){
        $data = self::where($where)
            ->where('order_delete', 1)
            ->field($field)
            ->order('order_time desc')
            ->page($page, self::$limit)
            ->select()
            ->toArray();
        return $data;
    }

    /**
     * 更新订单
     * @param $where
     * @param $update
     * @return Order
     */
    static function updateOrder($where = [], $update = []){
        return self::where($where)->update($update);
    }

    /**
     * 查询单条
     * @param $where
     * @param $field
     * @return array|bool|\PDOStatement|string|\think\Model|null
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    static function findOrder($where = [], $field = '*'){
        return self::where($where)->field($field)->find();
    }
}